<%-- 
    Document   : exam-manage
    Created on : Feb 14, 2012, 3:30:50 PM
    Author     : lab
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include  file="../handler/exam-manage-action.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Exam management</title>
        <link rel="stylesheet" type="text/css" href="../style/calendar.css"/>
        
        <script type="text/javascript">
            function remove(){             
                
                var deleteQuestion=($('#delete-question:checked').val()=="on");
                var idx=$('#selected-item-id').val();                   
                $.ajax({
                    type:"POST",
                    url:"../handler/exam-remove-action.jsp",
                    data:"id="+idx+"&delete-question="+deleteQuestion,
                    success:function(msg){
                        if(msg.trim()=='1'){
                            alert("Exam is deleted");
                            $('#row-'+idx).remove();
                        }else{
                            alert('Action failed');
                        }
                    }
                
                }
            );            
            }
            function setValue(idx){
                document.getElementById("selected-item-id").value=idx;
            }
            $(document).ready(function(){
                $('#start-time').datepicker();
                $('#end-time').datepicker();
            });
        </script>
    </head>
    <body>        
        <table class="data-table">
            <tr>
                <th>Exam</th>
                <th>Time</th>
                <th>Created date</th>
                <th>Public</th>
                <th></th>
            </tr>
            <c:forEach var="e" items="${list}">
                <tr id="row-${e.id}">
                    <td>${e.name}</td>
                    <td>${e.time}</td>
                    <td>${e.createdDate}</td>
                    <td>${e.state}</td>
                    <td>
                        <a href="?pcontent=exam-details&exid=${e.id}">Open</a> - 
                        <a href="?pcontent=manage-question&exid=${e.id}">Collect question</a> - 
                        <a href="javascript:showConfirm();" onclick="setValue(${e.id});">Delete</a> -
                        <a href="../public/index.jsp?pcontent=exam&id=${e.id}">Join in</a>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <input type="hidden" id="selected-item-id" name="selected-item-id"/>
        <div id="paging-bar">${pagingNav}</div>
        <div class="confirm-box">
            <div id="confirm-message">Are you sure want to continue?</div>
            <div id=""><input type="checkbox" name="delete-question" id="delete-question"/> Also delete question from database</div>
            <input type="button" onclick="remove();" value="Delete"/>
            <input type="button" onclick="hideConfirm();" value="Cancel"/>

        </div>
        <form method="post" action="#">
            <table>
                <tr>
                    <td>Exam name:</td>
                    <td><input type="text" name="name" id="name"/></td>
                    <td></td>
                </tr>
                <tr>
                    <td>Start time:</td>
                    <td><input type="text" name="start-time" id="start-time"/></td>
                    <td></td>
                </tr>
                <tr>
                    <td>End time</td>
                    <td><input type="text" name="end-time" id="end-time"/></td>
                    <td></td>
                </tr>
                <tr>
                    <td>Time:</td>
                    <td><input type="text" name="time" id="time"/></td>
                    <td></td>
                </tr>
                <tr>
                    <td>Public</td>
                    <td><input type="checkbox" name="is-public"/></td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" name="add" value="Create exam"/></td>
                    <td></td>
                </tr>
            </table>
        </form>
    </body>
</html>
